<?php
		
	header('Content-type:text/html;charset=utf-8');
	//后台登录页面
	class AdminAction extends Action{
		
		//加载对应的登录页面模版
		public function login(){
			$this->display('login');
		}
		
		//登录成功时
		public function succ(){
			
			$capt=$_POST['captcha'];
			if(session('verify')!= md5($capt)){
				$this->error('验证码不正确','login');
			}

			//接受用户提交的数据
			if(isset($_POST['submit'])){
				$username=$_POST['username'];
				$password=$_POST['password'];
			
				$admin=D('Admin');
				
				$count=$admin->where("a_username='$username' and a_password=MD5('$password')")->count();
				if($count>0){
					$a_ip=$_SERVER['REMOTE_ADDR'];
					$time=time();
					
					
					$save=$admin->where("a_username='$username'")->save(array(
							'a_last_ip'=>$a_ip,
							'a_last_time'=>$time
					));
				
					session('a_time',$time);
					session('a_ip',$a_ip);
					session('username',$username);
					cookie('username',$username,'60');
					$this->redirect('Index/index',array(),3,'系统登录中···');
					
				}else{
					$this->error('登录失败','login');
				}				
			}
			}
			
			//验证码类
			public function createcaptcha(){
				import('ORG.Util.Image');
				//调用验证码静态方法
				Image::buildImageVerify();
				
			}		
		}
		